<!doctype html>
<html>
<head>
	<#include "/pay/include/head_view.html" />
	<style>


	</style>
</head>

<body>

<div class="user_in" id="app">
	<i-form ref="myForm" :model="myform" :rules="ruleValidate" :label-width="10">
		<table id="sample-table-1" class="table table-striped table-bordered table-hover">
			<tbody>
			<tr height="35px">
				<td width="15%">
					商户uid:
				</td>
				<td width="35%">
					{{myform.uuid}}
				</td>
				<td width="15%">
					商户账号:
				</td>
				<td width="35%">
					{{myform.useracc}}
				</td>
			</tr>
			<tr>
				<td>
					商户sign_key:
				</td>
				<td>
					{{bus.signKey}}
					<i-button type="info" icon="shuffle" @click="reSetSignKey"> 重置 </i-button>
				</td>
				<td>
					商户名称:
				</td>
				<td>
					<Form-item label="" prop="nikename">
						<i-Input v-model="myform.nikename" placeholder="商户名称" style="width: 90%" ></i-Input>
					</Form-item>
				</td>
			</tr>
			<tr>
				<td>
					回调地址:
				</td>
				<td>
					<Form-item label="" prop="notifyUrl">
						<i-Input v-model="myform.notifyUrl"  placeholder="回调地址" style="width: 90%" ></i-Input>
					</Form-item>
				</td>
				<td>
					跳转地址:
				</td>
				<td>
					<Form-item label="" prop="gobackUrl">
					<i-Input v-model="myform.gobackUrl" placeholder="跳转地址" style="width: 90%" ></i-Input>
					</Form-item>
				</td>
			</tr>


			<tr>
				<td>
					email地址:
				</td>
				<td>
					<Form-item label="" prop="email">
					<i-Input v-model="myform.email" placeholder="email,找回密码使用" style="width: 90%" ></i-Input>
					</Form-item>
				</td>
				<td>
					QQ号码:
				</td>
				<td>
					<Form-item label="" prop="qq">
					<i-Input v-model="myform.qq" placeholder="qq" style="width: 90%" ></i-Input>
					</Form-item>
				</td>
			</tr>

			<tr>
				<td>
					自动续费:
				</td>
				<td>
					<Form-item label="" prop="autoReFee">
						<i-select v-model="bus.autoReFee" :value="bus.autoReFee">
							<i-option value="0">不自动续费</i-option>
							<i-option value="1">自动续费至-基础版</i-option>
							<i-option value="2">自动续费至-高级版</i-option>
							<i-option value="3">自动续费至-专业版</i-option>
						</i-select>
					</Form-item>
				</td>
				<td>
					二维码过期时间:
				</td>
				<td>
					<Form-item label="" prop="payTimeOut">
						<i-select v-model="bus.payTimeOut" :value="bus.payTimeOut">
							<i-option value="5">5分钟</i-option>
							<i-option value="10">10分钟</i-option>
							<i-option value="15">15分钟</i-option>
						</i-select>
					</Form-item>
				</td>
			</tr>

			<tr>
				<td>
					微信收款码:

				</td>
				<td>
					<template>
					<Upload action="/api/pay/paybus/upload_qr_img?payType=1"  name="uploadfile">
						<i-Button type="primary" icon="ios-cloud-upload-outline">上传不定额微信收款码</i-Button>
					</Upload>
					</template>
					<i-Button type="success" icon="search" @click="Imgview(1)">查看当前已上传收款码</i-Button>
				</td>
				<td>
					支付宝收款码:
				</td>
				<td>
					<template>
					<Upload action="/api/pay/paybus/upload_qr_img?payType=2"  name="uploadfile">
						<i-Button type="primary" icon="ios-cloud-upload-outline">上传不定额支付宝收款码</i-Button>
					</Upload>
					</template>
					<i-Button type="success"  icon="search"  @click="Imgview(2)">查看当前已上传收款码</i-Button>
				</td>
			</tr>

			</tbody>
		</table>


	<div>
		<i-button type="info" icon="shuffle" @click="save" long> 保 存 设 置 </i-button>

	</div>
</div>


</body>
	<script>
        var urls = {
            query:'/api/sys/sysuser/queryCurrUser'
            ,querybus:'/api/pay/paybus/queryCurrBus'
            ,reSetSignKey:'/api/pay/paybus/reSetSignKey'
            ,save:'/api/sys/sysuser/saveCurrUser'
            ,savebus:'/api/pay/paybus/saveCurrBus'
        };

        var vm = new Vue({
            el: '#app',
            data: {
                    myform: {
                        isState:true,
                        state: 1,
                        restype:1,
                        id:null,//主键
						test:"",
                        notifyUrl:"",
                        gobackUrl:""
                    },
					bus: {
						isState:true,
						state: 1,
                        notifyUrl:"",
                        gobackUrl:""
					},
                    ruleValidate: {
                        email: [
                            { required: true, message: '请输入邮箱地址', trigger: 'blur' },
                            { type: 'email', message: '邮箱地址格式不对', trigger: 'blur' }
                        ],
                        qq: [
                            { required: false, message: '请输入QQ号码', trigger: 'blur' },
                            { type: 'string', message: 'QQ号码格式不对', trigger: 'blur',pattern: /^[0-9]+$/ }
                        ],
                        notifyUrl: [
                            { required: true, message: '请输入回调地址', trigger: 'blur' },
                            { type: 'url', message: '回调地址必须是http://格式的地址', trigger: 'blur' }
                        ],
                        gobackUrl: [
                            { required: true, message: '请输入跳转地址', trigger: 'blur' },
                            { type: 'url', message: '跳转地址必须是http://格式的地址', trigger: 'blur' }
                        ]
                    }
            },
            created:function(){
                this.loadData();
            },
            methods: {
                loadData:function(){
                    $.ajax(
                        {
                            type: 'post', // 提交方式 get/post
                            url:urls.query, // 需要提交的 u
                            async:true,
                            cache:false,
                            dataType:'json',
                            success: function(ret){
                                if(ret.success){
                                    vm.myform = ret.data;
                                    vm.loadBus();
                                }else{
                                    layer.alert("您还没登录，或登录超时，请重新登录");
                                    window.top.location.href="/pay/login.html";
                                }
                            },
                            error:function(){
                                layer.alert("系统错误，请稍候再试");
                            }
                        });
                },
                loadBus:function(){
                    $.ajax(
                        {
                            type: 'post', // 提交方式 get/post
                            url:urls.querybus, // 需要提交的 u
                            async:true,
                            cache:false,
                            dataType:'json',
                            success: function(ret){
                                if(ret.success){
                                    vm.bus = ret.data;
                                    vm.bus.autoReFee=vm.bus.autoReFee+'';
                                    vm.bus.payTimeOut=vm.bus.payTimeOut+'';
                                    vm.myform.notifyUrl=vm.bus.notifyUrl;
                                    vm.myform.gobackUrl=vm.bus.gobackUrl;
                                    vm.myform.signKey=vm.bus.signKey;
                                }
                            },
                            error:function(){
                                layer.alert("系统错误，请稍候再试");
                            }
                        });
                },
                reSetSignKey:function(){
                    layer.confirm('重置将会使得之前的sign_key马上失效，确认需要进行重置么?', function(){
                        $.ajax(
                            {
                                type: 'post', // 提交方式 get/post
                                url:urls.reSetSignKey, // 需要提交的 u
                                async:true,
                                cache:false,
                                dataType:'json',
                                success: function(ret){
                                    if(ret.success){
                                        vm.bus.signKey = ret.data;
                                    }
                                },
                                error:function(){
                                    layer.alert("系统错误，请稍候再试");
                                }
                            });
                        layer.closeAll('dialog');
                    });
                },
                Imgview:function(payType){//查看支付二维码
                    layer.open({
                        type: 2,
                        title: '查看支付二维码',
                        maxmin: true,
                        shadeClose: true, //点击遮罩关闭层
                        area : ['400px' , '400px'],
                        content: '/api/pay/paybus/qr_img_view?payType='+payType
                    });
                },
                save:function () {
                    this.$refs['myForm'].validate(function(valid){
                        if (valid) {
                            $.ajax(
                                {
                                    type: 'post', // 提交方式 get/post
                                    url:urls.save, // 需要提交的 u
                                    async:true,
                                    cache:false,
                                    dataType:'json',
									data:vm.myform,
                                    success: function(ret){
                                        if(ret.success){
                                            layer.alert('保存成功!','success');
                                        }else{
                                            layer.alert(ret.msg);
                                        }
                                    },
                                    error:function(){
                                        layer.alert("系统错误，请稍候再试");
                                    }
                                });
                            //通知地址保存到商户表
                            vm.bus.notifyUrl=vm.myform.notifyUrl;
                            vm.bus.gobackUrl=vm.myform.gobackUrl;
                            $.ajax(
                                {
                                    type: 'post', // 提交方式 get/post
                                    url:urls.savebus, // 需要提交的 u
                                    async:true,
                                    cache:false,
                                    dataType:'json',
                                    data:vm.bus,
                                    success: function(ret){

                                    },
                                    error:function(){
                                        layer.alert("系统错误，请稍候再试");
                                    }
                                });
                        } else {
                            //PB.alert('表单验证失败!');
                            //PB.formPageSaveError();
                        }
					});
                }
            }
        });


	</script>

<#include "/pay/include/hmt.html" />
</html>
